/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxinline.manager.utilitario;

import br.com.foxinline.manager.pesquisar.ManagerPesquisarGenerico;
import br.com.foxinline.modelo.CadastroIndividual;
import br.com.foxinline.modelo.MicroArea;
import br.com.foxinline.modelo.QuestionarioAutoReferido;
import br.com.foxinline.servico.CadastroIndividualServico;
import br.com.foxinline.servico.MicroAreaServico;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import org.primefaces.event.ItemSelectEvent;
import org.primefaces.model.chart.PieChartModel;

/**
 *
 * @author ely
 */
@ManagedBean
@ViewScoped
public class ManagerPieModel extends ManagerPesquisarGenerico<CadastroIndividual> {

    @EJB
    CadastroIndividualServico cadastroIndividualServico;
    @EJB
    MicroAreaServico microAreaServico;
    private PieChartModel pieModel;
    private PieChartModel pieModelMicro;
    private String nomeDoenca;
    private List<CadastroIndividual> lstDiabetes;
    private List<CadastroIndividual> cadastroIndividuals;
    private CadastroIndividual cadastroIndividual;
    private List<MicroArea> microAreas;

    @PostConstruct
    @Override
    public void init() {
        visualizarPieModel();
        microAreas = new ArrayList<MicroArea>();
        cadastroIndividual = new CadastroIndividual();
        setServico(cadastroIndividualServico);
    }

    public void visualizarPieModel() {
        pieModel = new PieChartModel();

        pieModel.set("AVC", qtdAvc());
        pieModel.set("Câncer", qtdCancer());
        pieModel.set("Diabetes", qtdDiabetes());
        pieModel.set("Dsts Aids", qtdDstsAids());
        pieModel.set("Doença Cardíaca", qtdDoencaCardiaca());
        pieModel.set("Doença Pulmonar", qtdDoencaPulmonar());
        pieModel.set("Doença Renal", qtdDoencaRenal());
        pieModel.set("Hipertensão", qtdHipertensao());
        pieModel.set("Tuberculose", qtdTuberculose());


        pieModelMicro = new PieChartModel();
        microAreas = microAreaServico.pesquisarTodos();
        for (MicroArea m : microAreas) {
            pieModelMicro.set(m.getNome(), microAreaServico.QtdFamiliaMicroArea(m));
        }

    }

    public void itemSelect(ItemSelectEvent event) {

        cadastroIndividual = new CadastroIndividual();
        cadastroIndividual.setQuestionarioAutoReferido(new QuestionarioAutoReferido());

        if (event.getItemIndex() == 0) {
            nomeDoenca = "AVC";
            cadastroIndividual.getQuestionarioAutoReferido().setAvc(Boolean.TRUE);

        }
        if (event.getItemIndex() == 1) {
            nomeDoenca = "Câncer";
            cadastroIndividual.getQuestionarioAutoReferido().setCancer(Boolean.TRUE);

        }
        if (event.getItemIndex() == 2) {
            nomeDoenca = "Diabetes";
            cadastroIndividual.getQuestionarioAutoReferido().setDiabetes(Boolean.TRUE);
        }
        if (event.getItemIndex() == 3) {
            nomeDoenca = "DSTS / Aids";
            cadastroIndividual.getQuestionarioAutoReferido().setDstsAids(Boolean.TRUE);

        }
        if (event.getItemIndex() == 4) {
            nomeDoenca = "Doença Cardíaca";
            cadastroIndividual.getQuestionarioAutoReferido().setPossuiDoencaCardiaca(Boolean.TRUE);

        }
        if (event.getItemIndex() == 5) {
            nomeDoenca = "Doença Pulmonar";
            cadastroIndividual.getQuestionarioAutoReferido().setPossuiDoencaPulmonar(Boolean.TRUE);

        }
        if (event.getItemIndex() == 6) {
            nomeDoenca = "Doença Renal";
            cadastroIndividual.getQuestionarioAutoReferido().setPossuiProblemaRenal(Boolean.TRUE);

        }
        if (event.getItemIndex() == 7) {
            nomeDoenca = "Hipertensão";
            cadastroIndividual.getQuestionarioAutoReferido().setHipertensao(Boolean.TRUE);

        }
        if (event.getItemIndex() == 8) {
            nomeDoenca = "Tuberculose";
            cadastroIndividual.getQuestionarioAutoReferido().setTuberculose(Boolean.TRUE);

        }

        entidadePesquisar = cadastroIndividual;
        getSearchResults().setFirst(0);
        onLoadModel();

    }

    private Long qtdDiabetes() {
        return cadastroIndividualServico.QtdPacienteDiabetes();
    }

    private Long qtdCancer() {
        return cadastroIndividualServico.QtdPacienteCancer();
    }

    private Long qtdAvc() {
        return cadastroIndividualServico.QtdPacienteAVC();
    }

    private Long qtdTuberculose() {
        return cadastroIndividualServico.QtdPacienteTuberculose();
    }

    private Long qtdHipertensao() {
        return cadastroIndividualServico.QtdPacienteHipertensao();
    }

    private Long qtdDoencaPulmonar() {
        return cadastroIndividualServico.QtdPacientePossueDoencaPulmonar();
    }

    private Long qtdDoencaCardiaca() {
        return cadastroIndividualServico.QtdPacientePossueDoencaCardiaca();
    }

    private Long qtdDoencaRenal() {
        return cadastroIndividualServico.QtdPacientePossuiDoencaRenal();
    }

    private Long qtdDstsAids() {
        return cadastroIndividualServico.QtdPacienteDstsAids();
    }

    public PieChartModel getPieModel() {
        return pieModel;
    }

    public void setPieModel(PieChartModel pieModel) {
        this.pieModel = pieModel;
    }

    public String getNomeDoenca() {
        return nomeDoenca;
    }

    public void setNomeDoenca(String nomeDoenca) {
        this.nomeDoenca = nomeDoenca;
    }

    public List<CadastroIndividual> getCadastroIndividuals() {
        return cadastroIndividuals;
    }

    public void setCadastroIndividuals(List<CadastroIndividual> cadastroIndividuals) {
        this.cadastroIndividuals = cadastroIndividuals;
    }

    @Override
    public void limpar() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void remover() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public PieChartModel getPieModelMicro() {
        return pieModelMicro;
    }

    public void setPieModelMicro(PieChartModel pieModelMicro) {
        this.pieModelMicro = pieModelMicro;
    }
}
